# quizConsole.py - The actual consol program

from fileProcessing import *
from responseProcessing import *
from consoleLogic import *

#Create the consoleLogic and fileProcessing object
console=consoleLogic()
fileProc=fileProcessing()

#Select the roster file and the configuration file from the current directory
console.selectFiles(['roster file','configuration file'],['.csv','.conf'])
rosterFile=console.selectedFiles[0]
confFile=console.selectedFiles[1]

#Set the user
user=fileProc.getUser(confFile)

#Get the password and number of questions
password=console.getPassword()
numOfQuestions=console.getNumOfQuestions()

#Sets up respons object, connects, and clears inbox
responseProc=responseProcessing(numOfQuestions)

responseProc.user(user)
responseProc.pass_(password)

print 'Connecting...'
responseProc.connect()

print 'Clearing inbox...'
responseProc.clearInbox()

#Starts the collection loop and continues on keyboard interrupt
console.collectionLoop(responseProc)

#Disconnects from gmail
responseProc.disconnect()

#Writes response file
fileProc.writeResultFile(rosterFile,responseProc.responses,numOfQuestions)

#Sort the responses for display
responseProc.sortResponses()

#Displays top responses
console.displayTopResponses(responseProc.sortedResponses)

#Holds for enter
console.hold()


